package com.jzxy.PingFen.mapper;

import com.jzxy.PingFen.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * ClassName:AllMapper
 * Package:com.jzxy.PingFen.mapper
 * Description:
 *
 * @Author: dlh
 * @Creat:2025/1/13-14:56
 */
@Mapper
public interface AllMapper {
    @Select("Select * from user WHERE user_id=#{userId} and password =#{password};")
    User login(User user);
    @Select("Select * from user WHERE user_id=#{username};")
    User selectUser(String username);

    //先联查user和tb_user_role表得到role_id,再联查tb_role_menu得到menu_id,再查询tb_menu表得到具体权限
    @Select("SELECT \n" +
            "    m.menu_name\n" +
            "FROM \n" +
            "    user u\n" +
            "JOIN \n" +
            "    tb_user_role ur ON u.user_id = ur.user_id\n" +
            "JOIN \n" +
            "    tb_role_menu rm ON ur.role_id = rm.role_id\n" +
            "JOIN \n" +
            "    tb_menu m ON rm.menu_id = m.id\n" +
            "WHERE \n" +
            "    u.user_id = #{userId};")
    List<String> selectAuthentication(String userId);
    @Select("Select role_id from tb_user_role WHERE user_id=#{username};")
    Integer selectAuthentication1(String userId);
    @Select("Select menu_id from tb_role_menu WHERE role_id=#{roleId};")
    List<Integer> selectAuthentication2(Integer roleId);

    @Select("<script>" +
            "SELECT menu_name " +
            "FROM tb_menu " +
            "WHERE id IN " +
            "<foreach item='item' collection='menuIdList' open='(' separator=',' close= ')' index='index'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<String> selectAuthentication3(List<Integer> menuIdList);
}
